package com.asc.matchers {
import com.asc.Identifiable;

import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Matcher;

/**
 * Ensure that two identifiable items are equivalent
 */
public class IdentityMatcher implements Matcher{

  private var _item:Identifiable

  public function IdentityMatcher(_item:Identifiable) {
    this._item = _item;
  }

  public function describeTo(description:Description):void {
    description.appendText("Ensure two identifiable items are equivalent");
  }

  public function describeMismatch(item:Object, mismatchDescription:Description):void {
    mismatchDescription.appendText(
      "[" + _item + "]" +
       " does not equal [" +
        item + "]"
    );
  }

  public function matches(item:Object):Boolean {
    if(item is Identifiable) {
      const i:Identifiable = item as Identifiable;
      return _item.equals(i) && i.equals(_item);
    }
    return false;
  }
}
}